package com.hioove.jvm;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

/**
 * -XX:+PrintGCDetails
 * -XX:+PrintCommandLineFlags
 * -XX:+PrintGCDateStamps
 * -XX:MetaspaceSize=1000k
 * -XX:MaxMetaspaceSize=9900k
 * <p>
 * Exception in thread "main" java.lang.OutOfMemoryError: Metaspace
 * at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:348)
 * at net.sf.cglib.proxy.Enhancer.generate(Enhancer.java:492)
 * at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:117)
 * at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294)
 * at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
 * at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:305)
 * at com.hioove.jvm.JavaMethodAreaOOM.main(JavaMethodAreaOOM.java:17)
 * </p>
 */
public class JavaMethodAreaOOM {
    public static void main(String[] args) {
        while (true) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(JavaMethodAreaOOM.class);
            enhancer.setUseCache(false);
            enhancer.setCallback((MethodInterceptor) (obj, method, ags, proxy) -> proxy.invokeSuper(obj, args));
            JavaMethodAreaOOM oom = (JavaMethodAreaOOM) enhancer.create();
        }
    }
}
